package com.example.childpositionapp.network;

import android.annotation.SuppressLint;
import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.Handler;
import android.os.IBinder;
import android.util.Log;

import androidx.annotation.Nullable;


public class BackService extends Service {
    Thread thread;

    protected Handler handler=new Handler();

    @Override
    public void onCreate() {
        super.onCreate();
        Log.d("INIT", "Backserver init on create");
//        new InitSocketThread(this,handler).start();
        thread=new InitSocketThread(this,handler);
        thread.start();
    }

    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        return new MyBinder();
    }
    public class MyBinder extends Binder {
        public BackService getMyService(){
            return BackService.this;
        }
    }
    /**
     * 在Service中定义这个方法，用于测试
     * @return
     */
    public String getAuthorName(){
        return "芜湖芜湖芜湖";
    }

    @SuppressLint("LongLogTag")
    @Override
    public void onDestroy() {
        super.onDestroy();
        Log.d("88888888888888888888888888888888888888888","server end");
        if (InitSocketThread.mWebSocket != null) {
           InitSocketThread.mWebSocket.close(1000, null);
        }
    }

    public static void main(String[] args) {
        BackService service=new BackService();
        service.onCreate();
    }
}

